import tensorflow as tf2
tf = tf2.compat.v1
# 要在Tensorflow2 中执行1.x的代码，必须先执行下面这句！
tf.disable_eager_execution()

# ======= 会话 ========
node1 = tf.Variable(3.0, tf.float32, name='node1')
node2 = tf.Variable(4.0, tf.float32, name='node2')
result = tf.add(node1, node2, name='add')

sess = tf.Session()

# 变量的全局初始化
init = tf.global_variables_initializer()
# 注意：以上只是建立了一个init节点，需要Session去执行
sess.run(init)

print(sess.run(result))

# ======= 变量赋值 ========
# value = tf.Variable(0, name='value')
# one = tf.constant(1)
# new_value = tf.add(value, one)
# update_value = tf.assign(value, new_value)
# # update_value = tf.assign(value, value + one)
#
# sess = tf.Session()
# sess.run(tf.global_variables_initializer())
# for _ in range(10):
#     sess.run(update_value)
#     print(sess.run(value))
